package org.crazyit.cloud;

import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

@Configuration
public class MyConfig {

	@Bean
	@RefreshScope
	public Person person(Environment env) {
		// 读取名字创建Person实例
		String name = env.getProperty("test.user.name");
		// 输出Person名字
		System.out.println("初始化 person bean: " + name);
		// 创建一个Person
		Person p = new Person();
		p.setName(name);
		return p;
	}

	static class Person {

		private String name;

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}
	}
}
